package com.nuo.modules.video.controller;

import java.util.Arrays;
import java.util.Map;

import com.nuo.common.threadlocal.ThreadLocalDemo;
import com.nuo.common.utils.InfoUtils;
import com.nuo.modules.teacher.entity.TeacherEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.nuo.modules.video.entity.VideoEntity;
import com.nuo.modules.video.service.VideoService;
import com.nuo.common.utils.PageUtils;
import com.nuo.common.utils.R;



/**
 *
 *
 * @author nuo
 * @email 3033616351@qq.com
 * @date 2022-11-04 17:10:21
 */
@RestController
@RequestMapping("video")
@CrossOrigin("*")
public class VideoController {
    @Autowired
    private VideoService videoService;

    @Autowired
    InfoUtils<TeacherEntity> infoUtils;

    @Autowired
    ThreadLocalDemo threadLocalDemo;


    /**
     * 获取视频详情
     */
    @GetMapping("/getVideo")
    public R getVideo(@RequestParam Long id){
        // 视频观看数 + 1
        VideoEntity video = videoService.getById(id);
        video.setSeeNum(video.getSeeNum() + 1);
        videoService.updateById(video);
        return R.ok().put("video", video);
    }


    /**
     * 前台获取视频列表
     */
    @GetMapping("/getVideoList")
    public R getVideoList(){
        return R.ok().put("videoList", videoService.list());
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
        public R list(@RequestParam Map<String, Object> params){
        PageUtils page = videoService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
        public R info(@PathVariable("id") Long id){
		VideoEntity video = videoService.getById(id);

        return R.ok().put("video", video);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
        public R save(@RequestBody VideoEntity video){
		videoService.save(video);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
        public R update(@RequestBody VideoEntity video){
		videoService.updateById(video);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
        public R delete(@RequestBody Long[] ids){
		videoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
